package com.bdzl;


import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.context.request.RequestContextListener;

import java.util.stream.Collectors;

@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class ApplicationGeteway {

	public static void main(String[] args) {
		SpringApplication.run(ApplicationGeteway.class, args);
		System.out.println("起飛了大古！");
	}

	/**
	 * 监听器：监听HTTP请求事件
	 * 解决RequestContextHolder.getRequestAttributes()空指针问题
	 * @return
	 */
	@Bean
	public RequestContextListener requestContextListener(){
		return new RequestContextListener();
	}
	/**
	* @Description: TODO 不添加此配置会导致geteway无法进行openfign调用
	* @Author: Ming
	* @Date: 2021/5/7 12:02
	*/
	@Bean
	@ConditionalOnMissingBean
	public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
		return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
	}

}
